import { createRouter, createWebHashHistory } from 'vue-router'
import routes from "./routes"
import { useUserStore } from '@/stores/user'

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: routes,
})


router.beforeEach((to) => {
  const userStore = useUserStore();
  // console.log("token", userStore.token);
  console.log("token", userStore.isLogin);
  console.log("to", to);
  console.log(router);


  if (to.meta.Auth == true) { // 当前页面需要登录
    if (userStore.isLogin == false) { // 但是没有登录 
      // router.currentRoute  当前路由信息 => ref对象
      console.log("去登录");
      router.replace({ name: "login", query: { ReturnUrl: to.fullPath } })
    }
  }



  return true;
})



export default router
